const app= getApp();

Page({

    /**
     * 页面的初始数据
     */
    data: {

    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        console.log('-----coupon---options----')
        console.log(options)
        console.log('----coupon----options----')
        let that=this;
        var parent_id=options.parent_id;

        if(parent_id!=undefined){
            this.setData({
                parent_id:parent_id
              })
              wx.setStorageSync('parent_id',parent_id);
        }else{
            parent_id = wx.getStorageSync('parent_id');
        }
 
        wx.showShareMenu({
            menus: ['shareAppMessage', 'shareTimeline'],
            success(res) {
              console.log(res)
            },
            fail(e) {
              console.log(e)
            }
          })       
          var pages = getCurrentPages();
      console.log(pages);   

        var deviceInfo = wx.getDeviceInfo();   
        
      let d = app.globalData;
        that.setData({
            width:d.windowWidth,
            height:d.windowHeight,
            statusBarHeight:d.statusBarHeight,
            navHeight:d.navHeight,
            marginTop:d.navTitleTop,
            bottom:d.bottom,
            domain:d.domain,
            imgUrl:d.imgUrl,
            platform:deviceInfo.platform
          })
    },
   
      goIndex:function(){
        wx.reLaunch({
          url: '../index/index',
        })
      },
  
      goto(e){
        console.log(e);
        var url=e.currentTarget.dataset.url;
        console.log(url);
        var index=e.currentTarget.dataset.index;
        app.goto(url,index)
      // console.log(url);
    },

    getIndex:function(){
        let that = this;    
        let d = this.data;
        console.log('coupon----getIndex')  
        var store_id = wx.getStorageSync('store_id');
        var open = wx.getStorageSync('open');
        //var parent_id = d.
        wx.request({
          url: app.globalData.domain+'/wechat/scheme/Index',
          data:{from:1,user_id:open.user_id,parent_id:d.parent_id},
          success:res=>{
              console.log(res)
              var d=res.data;
           
            that.setData({
            servicePhone:d.servicePhone,
            data:d.list
         

            })
          }
      })

    },

    call(e){
        console.log(e);
        var callPhone = e.currentTarget.dataset.phone;
        wx.makePhoneCall({//调用拨打电话的函数
            phoneNumber: callPhone,
          })
  
    },
  
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
    
    this.getIndex();
     //var tabIndex=1;
 let that = this;
 var  tab = wx.getStorageSync('tabBar');
if(tab == '' || tab == undefined){
  app.getMenu();
  setTimeout(function(){ 
  //console.log("延时1秒后执行");
    that.getTabBar().init('storeWait');
}, 1000);
}else{
  this.getTabBar().init('store');
}    
       
        },

  
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {
        console.log(this.data.couponTimer);
        clearInterval(this.data.couponTimer);
    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {
        clearInterval(this.data.couponTimer);
    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareTimeline(e){
        //console.log(e);
        var title=this.data.shareTitle;
        var shareLogo=this.data.shareLogo;
        var open=wx.getStorageSync('open');
        var store_id = wx.getStorageSync('store_id');
        var parent_id=open.id;
         this.setData({
           share:true
         });
         console.log(shareLogo);
         console.log(title);
         return{
           title: title,                 
           query: 'share=4&parent_id='+parent_id+'&store_id='+store_id,        
           imageUrl:shareLogo      
           }
       },
       onShareAppMessage(e) {
        var open = wx.getStorageSync('open');
        var parent_id=open.id;
        var store_id = wx.getStorageSync('store_id');
        var that = this;
        var title=this.data.shareTitle;
        var shareLogo=this.data.shareIndex;
   　  　var shareObj = {
   　　　　title: title,    
   　　　　path: '/pages/index/index?share=4&parent_id='+parent_id+'&store_id='+store_id,   
   　　　　imageUrl: shareLogo 
   　　　
   　　}
   　　// 来自页面内的按钮的转发
   　　if( e.from == 'button' ){
     　　　shareObj.title=title;
   　　　　shareObj.path = '/pages/index/index?share=4&parent_id='+parent_id+'&store_id='+store_id;
   　　}
   console.log(shareObj);
   　　// 返回shareObj
   　　return shareObj;
    }
})

